package org.bonorsoft.modules.education.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bonorsoft.modules.education.entity.Enclosure;

/**
 * @Description: 附件表
 * @Author: WilliamYe
 * @Date:   2021-06-22
 * @Version: V1.0
 */
public interface EnclosureMapper extends BaseMapper<Enclosure> {

    /**
     * 添加附件
     * @param uuid 附件表id
     * @param noticeResponseId 通知/回复表id
     * @param file 附件路径
     * @return
     */
    @Insert("insert into sys_enclosure(enclosure_id, notice_response_id, enclosure_name, enclosure_route) " +
            "values (#{uuid}, #{noticeResponseId}, #{fileName}, #{file})")
    boolean add(String uuid, String noticeResponseId, String fileName, String file);

    /**
     * 根据通知或回复id获取附件路径
     * @param noticeResponseId
     * @return
     */
    @Select("select enclosure_route from sys_enclosure " +
            "where notice_response_id = #{noticeResponseId}")
    String getFileByNoticeId(String noticeResponseId);

    /**
     * 根据通知或回复id查询附件数量
     * @param noticeResponseId
     * @return
     */
    @Select("select count(0) from sys_enclosure " +
            "where notice_response_id = #{noticeResponseId}")
    int countByNoticeId(String noticeResponseId);

    /**
     * 根据通知或回复id修改附件信息
     * @param noticeResponseId
     * @param file
     * @return
     */
    @Update("update from sys_enclosure " +
            "set enclosure_route = #{file} " +
            "where notice_response_id = #{noticeResponseId}")
    boolean save(String noticeResponseId, String file);

    /**
     * 根据通知或回复id删除附件
     * @param noticeResponseId
     * @return
     */
    @Delete("delete from sys_enclosure " +
            "where notice_response_id = #{noticeResponseId}")
    int deleteByNoticeId(String noticeResponseId);
}
